package com.itheima.info.manager.service;

import com.itheima.info.manager.dao.StudentDao;
import com.itheima.info.manager.domain.Student;

public class StudentService {

    private StudentDao studentDao = new StudentDao();

    public boolean addStudent(Student student) {
        return studentDao.addStudent(student);
    }

    public boolean isExist(String stuId) {
        Student[] stu = studentDao.findAllStudent();
        boolean flag = false;

        for (int i = 0; i < stu.length; i++) {
            Student s = stu[i];
            if (s != null && s.getId().equals(stuId)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public Student[] findAllStudent() {
        Student[] allStudent = studentDao.findAllStudent();
        boolean flag = false;
        for (int i = 0; i < allStudent.length; i++) {
            Student s = allStudent[i];
            if (s!=null){
                flag=true;
                break;
            }
        }

        if (flag){
            return allStudent;
        }else {
            return null;
        }
    }

    public void deleteStudentById(String stuId) {
        studentDao.deleteStudentById(stuId);
    }

    public void updateStudent(String updateId, Student newStu) {
        studentDao.updateStudent(updateId,newStu);
    }
}
